using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Speedball2 {
  public class Person {
    public int _offset;

    public int _pAttributes;
    public int _personAttributesIndex;
    public AttributesTypeEnum _personAttributesType;
    public string _name;
    public int _id;
    public Point _infoXY;

    public Person (byte [] bytes, int offset) {
      _offset = offset;

      //int pAttributes = (int) bytes.ReadLong (offset);
      //_attributesIndex = (pAttributes - Attributes.GetAttributesBaseAddress (pAttributes)) / Attributes.Size;
      //offset += 4;

      _pAttributes = (int) bytes.ReadLong (offset);
      _personAttributesIndex = (_pAttributes - Attributes.GetAttributesBaseAddress (_pAttributes, out _personAttributesType)) / Attributes.Size;
      offset += 4;

      int pName = (int) bytes.ReadLong (offset);
      _name = bytes.ReadString (Game.AtariRamToDisk (pName));
      offset += 4;

      _id = bytes.ReadWord (offset);
      offset += 2;

      _infoXY = new Point (bytes.ReadWordSigned (offset), bytes.ReadWordSigned (offset + 2));
      offset += 4;
    }

    public void CopySubstituteTo (Match match, Person personDst) {
      personDst._id = _id;
      personDst._name = _name;
      Attributes personAttributes = GetPersonAttributes (match);
      Attributes personAttributesDst = personDst.GetPersonAttributes (match);
      personAttributesDst._agr = personAttributes._agr;
      personAttributesDst._att = personAttributes._att;
      personAttributesDst._def = personAttributes._def;
      personAttributesDst._spd = personAttributes._spd;
      personAttributesDst._thr = personAttributes._thr;
      personAttributesDst._pow = personAttributes._pow;
      personAttributesDst._sta = personAttributes._sta;
      personAttributesDst._int = personAttributes._int;
    }

    public Attributes GetPersonAttributes (Match match) {
      return (match.GetPersonAttributes (_personAttributesIndex, _personAttributesType));
    }

    public static int Size {
      get {
        return (0xE);
      }
    }

    //public void Dump () {
    //  Console.Write ("{0:X2} ", _health);
    //  Console.Write ("{0:X2} ", _initialDir);
    //  Console.Write ("{0:X2} ", _pos);
    //  Console.WriteLine ();
    //  Console.Write ("{0:X2} ", _agr);
    //  Console.Write ("{0:X2} ", _att);
    //  Console.Write ("{0:X2} ", _def);
    //  Console.Write ("{0:X2} ", _spd);
    //  Console.Write ("{0:X2} ", _thr);
    //  Console.Write ("{0:X2} ", _pow);
    //  Console.Write ("{0:X2} ", _sta);
    //  Console.Write ("{0:X2} ", _int);
    //  Console.WriteLine ();
    //}
  }
}
